package Grammar.multiThread.AlternatePrint;

import lombok.SneakyThrows;

/**
 * @author liujun
 * @version 1.0
 * @date 2020/12/2
 * @author—Email liujunfirst@outlook.com
 * @blogURL https://blog.csdn.net/ljfirst
 * @description 交替多线程 解法二
 * 两个线程，一个存有数组1、2、3和另一个存有a、b、c，然后通过调度，最终结果输出1a2b3c
 */
public class AlternatePrint_Notify {

    static String[] array_alpha = {"A", "B", "C"};
    static int[] array_num = {1, 2, 3};

    public static void main(String[] args) {
     String ob = "we";
     String ob1 = "we1";

        Thread alpha = new Thread() {
            int count = 0;

            @SneakyThrows
            @Override
            public void run() {
                while (count < array_alpha.length) {

                    System.out.print(array_alpha[count] + " ");
                    ob1.notify();
                    ob.wait();
                }
            }
        };

        Thread num = new Thread() {
            int count = 0;

            @SneakyThrows
            @Override
            public void run() {
                while (count < array_num.length) {
                    System.out.print(array_num[count] + " ");

                    ob.notify();
                    ob1.wait();
                }
            }
        };

        num.start();
        alpha.start();
    }


}
